#include "cAck.h"

#include <sstream>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeIterator.h>
#include "misc/Interface.h"
#include "misc/Debug.h"
#include "client/Client.h"
#include "client/net/cAnnounce.h"
/*********************************************************/
void cAck::execute()
{
	Client& ns = Client::Instance();
	
	ns.mutex.lock();
	ACKMAP::iterator it = ns.ackmap.find(addr.toString());
	if ( it != ns.ackmap.end() ) {
		std::map<unsigned long, std::string>::iterator it2 = it->second.find(id);
		if ( it2 != it->second.end() ) {
			it->second.erase(it2);

			if ( it->second.size() == 0 ) {
				ns.ackmap.erase(it);
			}
			ns.mutex.unlock();
			return;
		}
	}
	ns.mutex.unlock();
}
/*********************************************************/
std::string cAck::serialize() const
{
	std::ostringstream		ostr;

	ostr << "<GS id='" << id << "'>";
	ostr << "<ACK></ACK>";
	ostr << "</GS>";

	return( ostr.str() );
}
/*********************************************************/
void cAck::deserialize(Poco::XML::NodeIterator& it)
{
	// This messages doesn't carry any specific data so we do nothing here
}
/*********************************************************/
